<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script type="text/javascript">
    function alertMsg(msg){
      alert(msg);
      event.cancelBubble = true;
    }
    function test(){
      var divcontent = document.getElementById("div1").innerHTML;
      console.log(divcontent);
      if(divcontent=="div1"){
        
        location = "http://www.baidu.com";
        
      }
    }
  </script>
  <style type="text/css">
    div{
      margin :30px;
      border : 1px solid red;
    }
  </style>
</head>
<body>
  <div onclick="alertMsg('div2')">
    <div style="height:100px;" onclick="alertMsg('div1')" id="div1">div</div>
  </div>

  <a href="http://www.baidu.com" onclick="return false;">baidu</a>

  <a href="javascript:void(0)" onclick="test()">baidu</a>
</body>
</html>